package com.fengmoxi.ctv.activity.config.lamp.vc;

import android.os.Bundle;
import android.view.KeyEvent;

import androidx.appcompat.app.AppCompatActivity;

import com.fengmoxi.ctv.R;
import com.fengmoxi.ctv.activity.config.lamp.ConfigLampActivity;
import com.fengmoxi.ctv.manage.HomeButtonReceiver;
import com.fengmoxi.ctv.manage.LampManage;

public class ConfigLampOpticalAlignmentActivity extends AppCompatActivity {
    private static final String TAG = ConfigLampOpticalAlignmentActivity.class.getSimpleName();
    private LampManage mLampManage;
    private HomeButtonReceiver mHomeButtonReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config_lamp_optical_alignment);

        mLampManage = new LampManage();

        mHomeButtonReceiver = new HomeButtonReceiver(this, new HomeButtonReceiver.OnHomeBtnPressListener() {
            @Override
            public void onHomeBtnPress() {
                if (ConfigLampActivity.configLampActivity != null) {
                    ConfigLampActivity.configLampActivity.finish();
                }
                finish();
            }

            @Override
            public void onHomeBtnLongPress() {

            }
        });
        mHomeButtonReceiver.start();
    }

    public boolean onKeyDown(int kCode, KeyEvent kEvent) {
        switch (kCode) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
            case KeyEvent.KEYCODE_DPAD_DOWN:
                mLampManage.OptAdjMinus();
                return true;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
            case KeyEvent.KEYCODE_DPAD_UP:
                mLampManage.OptAdjPlus();
                return true;
            case KeyEvent.KEYCODE_ENTER:
                mLampManage.OptAdjStart();
                return true;
        }
        return super.onKeyDown(kCode, kEvent);
    }

    @Override
    protected void onDestroy() {
        mLampManage.OptAdjExit();
        // 保存设置
        mLampManage.saveOptAdjUserParam();
        mHomeButtonReceiver.stop();
        super.onDestroy();
    }
}